package ${package.Controller};

import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;


import org.springframework.web.bind.annotation.RequestMapping;
<#if restControllerStyle>
    import org.springframework.web.bind.annotation.RestController;
<#else>
    import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
    import ${superControllerClassPackage};
</#if>

import javax.validation.Valid;
import java.util.List;
import com.kxn.multi.module.common.pojo.ApiResult;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
* <p>
* ${table.comment} 前端控制器
* </p>
*
* @author ${author}
* @since ${date}
*/
@Api(tags = "${table.comment}")
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Resource
    private ${table.serviceName} ${table.serviceName?uncap_first};

    <#if swagger>
    @ApiOperation(value = "${table.comment}分页列表", response = ${entity}.class)
    @ApiImplicitParams({
    @ApiImplicitParam(name = "pageSize", value = "页面", dataType = "Integer"),
    @ApiImplicitParam(name = "pageNum", value = "页面数据量", dataType = "Integer"),
    @ApiImplicitParam(name = "sort", value = "排序方式排序[true:正序; false:倒序]", dataType = "Boolean"),
    @ApiImplicitParam(name = "sortName", value = "排序字段,参照返回字段", dataType = "String")})
    <#else>
    /**
    * 分页列表
    */
    </#if>
    @PostMapping(value = "/page")
    public ApiResult list(@Valid @RequestBody ${entity} param) {
        IPage<${entity}> data  = ${table.serviceName?uncap_first}.page(param);
        return ApiResult.success(data);
    }

    <#if swagger>
    @ApiOperation(value = "${table.comment}详情", response = ${entity}.class)
    <#else>
    /**
    * 详情
    */
    </#if>
    @GetMapping(value = "/{id}")
    public ApiResult detail(@PathVariable Long id) {
        ${entity} data = ${table.serviceName?uncap_first}.detail(id);
        return ApiResult.success(data);
    }

    <#if swagger>
    @ApiOperation(value = "${table.comment}新增")
    <#else>
    </#if>
    @PostMapping(value = "/create")
    public ApiResult create(@Valid @RequestBody ${entity} param) {
        ${table.serviceName?uncap_first}.create(param);
        return ApiResult.success(param);
    }

    <#if swagger>
    @ApiOperation(value = "${table.comment}修改")
    <#else>
    /**
    * 修改
    */
    </#if>
    @PostMapping("/update/{id}")
    public ApiResult update(@PathVariable Long id, @Valid @RequestBody ${entity} param) {
        ${table.serviceName?uncap_first}.updateById(id, param);
        return ApiResult.success(param);
    }

    <#if swagger>
    @ApiOperation(value = "${table.comment}删除单个条目")
    <#else>
    /**
    * 删除单个条目
    */
    </#if>
    @GetMapping(value = "/delete/{id}")
    public ApiResult delete(@PathVariable Long id) {
        ${table.serviceName?uncap_first}.delete(id);
        return ApiResult.success();
    }

    <#if swagger>
    @ApiOperation(value = "${table.comment}删除多个条目")
    <#else>
    /**
    * 删除多个条目
    */
    </#if>
    @PostMapping(value = "/batchDel")
    public  Object batchDel(@Valid @RequestBody List<Long> ids) {
        ${table.serviceName?uncap_first}.batchDelete(ids);
        return ApiResult.success();
    }

}
</#if>